<html>
<head><meta charset="utf-8"><title>long jump inside asm! macro · general · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/index.html">general</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/long.20jump.20inside.20asm!.20macro.html">long jump inside asm! macro</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="215358586"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/long%20jump%20inside%20asm%21%20macro/near/215358586" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Soveu <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/long.20jump.20inside.20asm!.20macro.html#215358586">(Nov 02 2020 at 18:26)</a>:</h4>
<p>Is it possible to make long jumps inside asm! macro?<br>
I tried</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="n">asm</span><span class="o">!</span><span class="p">(</span><span class="s">"jmp 0x0008:{}"</span><span class="p">,</span><span class="w"> </span><span class="n">sym</span><span class="w"> </span><span class="n">long_jmp_target</span><span class="p">);</span><span class="w"></span>
</code></pre></div>
<p>but it does not work, instead i get this error</p>
<div class="codehilite"><pre><span></span><code>error: unexpected token in argument list
   --&gt; src/main.rs:172:10
    |
172 |         &quot;jmp 0x0008:{}&quot;,
    |          ^
    |
note: instantiated into assembly here
   --&gt; &lt;inline asm&gt;:2:12
    |
2   |     jmp 0x0008:_ZN10goodloader9long_mode17ha326a86a919e71f9E
    |               ^
</code></pre></div>



<a name="215360644"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/long%20jump%20inside%20asm%21%20macro/near/215360644" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Soveu <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/long.20jump.20inside.20asm!.20macro.html#215360644">(Nov 02 2020 at 18:44)</a>:</h4>
<p>(i686 target)</p>



<a name="215361860"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/long%20jump%20inside%20asm%21%20macro/near/215361860" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Soveu <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/long.20jump.20inside.20asm!.20macro.html#215361860">(Nov 02 2020 at 18:54)</a>:</h4>
<p>i can use segment selectors, but in order to change cs selector i need to do a jmp</p>



<a name="215378141"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/long%20jump%20inside%20asm%21%20macro/near/215378141" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Soveu <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/long.20jump.20inside.20asm!.20macro.html#215378141">(Nov 02 2020 at 21:01)</a>:</h4>
<p>i fixed it by <code>ljmp 0x0008, offset {}</code></p>



<a name="215384679"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/long%20jump%20inside%20asm%21%20macro/near/215384679" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/long.20jump.20inside.20asm!.20macro.html#215384679">(Nov 02 2020 at 21:55)</a>:</h4>
<p><span class="user-mention" data-user-id="328907">@Soveu</span> Are you building for x86-64 or i686?</p>



<a name="215483513"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/long%20jump%20inside%20asm%21%20macro/near/215483513" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Soveu <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/long.20jump.20inside.20asm!.20macro.html#215483513">(Nov 03 2020 at 17:14)</a>:</h4>
<p>as i said, its i686</p>



<a name="215545885"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/long%20jump%20inside%20asm%21%20macro/near/215545885" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/long.20jump.20inside.20asm!.20macro.html#215545885">(Nov 04 2020 at 06:36)</a>:</h4>
<p>(didn't see that part of the message, sorry)</p>



<a name="215545898"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/long%20jump%20inside%20asm%21%20macro/near/215545898" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/long.20jump.20inside.20asm!.20macro.html#215545898">(Nov 04 2020 at 06:37)</a>:</h4>
<p>This seems like a bug in LLVM's assembly parser.</p>



<a name="215545909"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/long%20jump%20inside%20asm%21%20macro/near/215545909" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/long.20jump.20inside.20asm!.20macro.html#215545909">(Nov 04 2020 at 06:37)</a>:</h4>
<p>Using ljmp is one workaround, directly encoding the instruction as bytes is another.</p>



<a name="215545956"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/long%20jump%20inside%20asm%21%20macro/near/215545956" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/long.20jump.20inside.20asm!.20macro.html#215545956">(Nov 04 2020 at 06:38)</a>:</h4>
<p>But LLVM <em>should</em> handle this in Intel syntax mode.</p>



<a name="215571077"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/long%20jump%20inside%20asm%21%20macro/near/215571077" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Soveu <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/long.20jump.20inside.20asm!.20macro.html#215571077">(Nov 04 2020 at 11:58)</a>:</h4>
<p><span class="user-mention silent" data-user-id="239881">Josh Triplett</span> <a href="#narrow/stream/122651-general/topic/long.20jump.20inside.20asm!.20macro/near/215545909">said</a>:</p>
<blockquote>
<p>Using ljmp is one workaround, directly encoding the instruction as bytes is another.</p>
</blockquote>
<p><code>db</code> doesn't work inside asm! macro<br>
instead i did</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="n">asm</span><span class="o">!</span><span class="p">(</span><span class="w"></span>
<span class="w">  </span><span class="s">"push bx"</span><span class="p">,</span><span class="w"></span>
<span class="w">  </span><span class="s">"push eax"</span><span class="p">,</span><span class="w"></span>
<span class="w">  </span><span class="s">"retf"</span><span class="p">,</span><span class="w"></span>
<span class="w">  </span><span class="k">in</span><span class="p">(</span><span class="s">"bx"</span><span class="p">)</span><span class="w"> </span><span class="mh">0x8</span><span class="p">,</span><span class="w"></span>
<span class="w">  </span><span class="k">in</span><span class="p">(</span><span class="s">"eax"</span><span class="p">)</span><span class="w"> </span><span class="n">jump</span><span class="p">,</span><span class="w"></span>
<span class="w">  </span><span class="n">options</span><span class="p">(</span><span class="n">nomem</span><span class="p">,</span><span class="w"> </span><span class="n">noreturn</span><span class="p">),</span><span class="w"></span>
<span class="p">)</span><span class="w"></span>
</code></pre></div>



<a name="215571190"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/long%20jump%20inside%20asm%21%20macro/near/215571190" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Soveu <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/long.20jump.20inside.20asm!.20macro.html#215571190">(Nov 04 2020 at 12:00)</a>:</h4>
<p>still, i can't force <code>push</code> to be a push with 16bit immediate, but maybe it will work with <code>pushw</code> on AT&amp;T syntax</p>



<a name="215620950"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/long%20jump%20inside%20asm%21%20macro/near/215620950" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/long.20jump.20inside.20asm!.20macro.html#215620950">(Nov 04 2020 at 18:17)</a>:</h4>
<p><span class="user-mention" data-user-id="328907">@Soveu</span> You can use <code>.byte</code>.</p>



<a name="215622495"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/long%20jump%20inside%20asm%21%20macro/near/215622495" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Soveu <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/long.20jump.20inside.20asm!.20macro.html#215622495">(Nov 04 2020 at 18:31)</a>:</h4>
<p><code>push .word 0x8</code>?</p>



<a name="215622840"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/long%20jump%20inside%20asm%21%20macro/near/215622840" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Soveu <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/long.20jump.20inside.20asm!.20macro.html#215622840">(Nov 04 2020 at 18:33)</a>:</h4>
<p>what is the syntax that asm macro uses?<br>
i know basic yasm intel syntax, this is pretty similar, but not quite</p>



<a name="215627901"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/long%20jump%20inside%20asm%21%20macro/near/215627901" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/long.20jump.20inside.20asm!.20macro.html#215627901">(Nov 04 2020 at 19:12)</a>:</h4>
<p><code>asm!(".byte 0x12", ".byte 0x34", ...)</code> would emit the bytes 0x12 and then 0x34 into the instruction stream.</p>



<a name="215627939"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/long%20jump%20inside%20asm%21%20macro/near/215627939" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/long.20jump.20inside.20asm!.20macro.html#215627939">(Nov 04 2020 at 19:12)</a>:</h4>
<p>So if you want to encode an instruction or instruction format that LLVM doesn't understand, you can do it that way.</p>



<a name="215628005"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/long%20jump%20inside%20asm%21%20macro/near/215628005" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/long.20jump.20inside.20asm!.20macro.html#215628005">(Nov 04 2020 at 19:13)</a>:</h4>
<p>You can't substitute it for one of the operands of an instruction; it's a separate line that just emits data.</p>



<a name="215628414"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/long%20jump%20inside%20asm%21%20macro/near/215628414" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Soveu <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/long.20jump.20inside.20asm!.20macro.html#215628414">(Nov 04 2020 at 19:16)</a>:</h4>
<p>oh, that way, thanks</p>



<a name="215629426"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/long%20jump%20inside%20asm%21%20macro/near/215629426" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Soveu <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/long.20jump.20inside.20asm!.20macro.html#215629426">(Nov 04 2020 at 19:25)</a>:</h4>
<p>the <code>att_syntax</code> works just fine for this one example</p>



<a name="215630427"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/long%20jump%20inside%20asm%21%20macro/near/215630427" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Soveu <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/long.20jump.20inside.20asm!.20macro.html#215630427">(Nov 04 2020 at 19:33)</a>:</h4>
<p>someone suggested on discord that <code>push word ptr 0x8</code> in intel syntax is <code>pushw $8</code> in att <span aria-label="thinking" class="emoji emoji-1f914" role="img" title="thinking">:thinking:</span></p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>